package com.example.tyz1201.myaccount.Activity.Activity.Activity;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.widget.ListView;

import com.example.tyz1201.myaccount.Activity.Activity.Adapter.AssumeAdapter;
import com.example.tyz1201.myaccount.Activity.Activity.Model.AssumeModel;
import com.example.tyz1201.myaccount.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Created by tyz1201 on 2016/4/12.
 */
public class MonthIncomeActivity extends AppCompatActivity {

    private int choosedAssumeTypeId;
    private String assumeData;
    private AssumeModel assumeModel;
    List<AssumeModel> monthIncomeMessages = new ArrayList<>();
    Map<String, String> map = new HashMap<>();
    Toolbar toolbar_month_income;
    ListView lv_month_income;
    AssumeAdapter assumeAdapter;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_month_income);

        toolbar_month_income = (Toolbar) findViewById(R.id.toolbar_month_income);
        toolbar_month_income.setTitle("本月收入");
        toolbar_month_income.setTitleTextColor(getResources().getColor(R.color.Black));
        setSupportActionBar(toolbar_month_income);

        lv_month_income = (ListView) findViewById(R.id.lv_month_income);
        initmonthIncomeMessages();

        assumeAdapter = new AssumeAdapter(monthIncomeMessages, MonthIncomeActivity.this);
        lv_month_income.setAdapter(assumeAdapter);

    }

    private void initmonthIncomeMessages() {
        SharedPreferences sharedPreferences = getSharedPreferences("account", MODE_PRIVATE);
        map = (Map<String, String>) sharedPreferences.getAll();
        Set<String> keySet = map.keySet();

        for (String key : keySet) {
            assumeData = map.get(key);
            assumeModel = AssumeModel.backToAssumeModel(assumeData);
            choosedAssumeTypeId = assumeModel.getChoosedAssumeTypeId();

            if (choosedAssumeTypeId == 1) {
                monthIncomeMessages.add(assumeModel);
            }
        }
    }
}
